package com.aqs;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author: csh
 * @Date: 2022/11/28 21:05
 * @Description:重入锁
 */
public class ReentrantLockTest {
    public static void main(String[] args) {
        // false（非公平锁） true(公平锁)
        ReentrantLock lock = new ReentrantLock(false);
        //加锁
        lock.lock();
        //尝试加锁 并且加上超时时间 避免无限等待
        //lock.tryLock(3000, TimeUnit.SECONDS);
        //判断是否上锁
        System.out.println(lock.isLocked());
        //解锁
        lock.unlock();
        //判断是否上锁
        System.out.println(lock.isLocked());
    }
}
